home *** CD-ROM | disk | FTP | other *** search
- /************************************************************
-
- FM-TOWNS Text Screen Editer Program
-
- 1989.7.27 v1.00 Make By Ken
-
- ************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <setjmp.h>
- #include <string.h>
- #define MAIN
- #include "defs.h"
-
- #ifdef FMR70
- #include <signal.h>
- #endif
-
- #ifdef TOWNS
- #include <egb.h>
- #include <fmc.h>
- #include <snd.h>
- #include "oaklib.h"
- #define unlink(f) remove(f)
- #endif
-
- extern void wrtstr();
- extern void Dsp_ins_mode();
- extern void Dsp_free();
- extern void Ins_buf();
- extern void Cut_buf();
- extern int Dsp_init();
- extern int Bfp_init();
- extern void Set_vram();
- extern void Dsp_vram();
- extern BOOL edit();
- extern int Del_wind();
- extern void Bfp_end();
- extern void RSB_end();
- extern void putstr();
- extern void putsys();
- extern void putmode();
- extern void Dmy_form();
- extern void Del_buf();
- extern void Auto_log_init();
- extern void CD_endof();
-
- extern UCHAR vram[];
- extern char *SPCSTR;
- extern char *Auto_log_file;
-
- extern short int modeW;
-
- char *work;
- jmp_buf mark;
- char *file_name=NULL;
- char *Tmp_device_name=NULL;
-
- static BOOL old_wrt_flg=ERR;
- static char tmp_name[160];
- static int Back_up = FALSE;
- static int Apend_Z = FALSE;
-
- void Start_Msg()
- {
- static char *msg[]={
- " WINK @ー ",
- " Multi Screen Text Editor ",
- " WINK [ver3.20.00] ",
- " Copyright (c) 1989,90 FTOWNS ",
- " Created by K.Miyazaki ",
- " thanks to RED++ ",
- NULL
- };
- int i;
- char tmp[160];
-
- Dmy_form(tmp,30,0x98,0x95,0x99);
- wrtstr(tmp,20,9,0x07);
- Dmy_form(tmp,30,0x96,0x20,0x96);
- for ( i = 0 ; msg[i] != NULL ; i++ ) {
- wrtstr(tmp,20,10+i,0x07);
- wrtstr(msg[i],21,10+i,i == 0 ? 0x14 : 0x07);
- }
- Dmy_form(tmp,30,0x9A,0x95,0x9B);
- wrtstr(tmp,20,16,0x07);
- wrtstr("WINK",25,12,0x16);
- }
- void Gra_init()
- {
- #ifdef TOWNS
- work = (char *)malloc(2048);
- memset(work,0,2048);
- EGB_init(work,2048);
- EGB_resolution(work, 0, 3);
- EGB_resolution(work, 1, 3);
- EGB_displayPage(work, 0, 3);
- EGB_pen(work,0);
- EGB_penSize(work,1);
- SND_elevol_init();
- SND_elevol_mute(0x30);
- SND_elevol_set(1,64,64);
- #endif
- }
- void Dsp_file_name()
- {
- char tmp[160];
-
- memset(tmp,' ',60); tmp[60] = '\0';
- wrtstr(tmp,0,1,0x1F);
- if ( file_name != NULL ) {
- sprintf(tmp," %-12s ",file_name);
- wrtstr(tmp,0,1,0x14);
- } else
- wrtstr(" [Not File] ",1,1,0x1F);
- }
- void Dsp_wrt_flg()
- {
- if ( Wrt_flg != old_wrt_flg ) {
- if ( (old_wrt_flg = Wrt_flg) == FALSE )
- wrtstr("表示",0,0,0x17);
- else
- wrtstr("編集",0,0,0x17);
- }
- }
- void Dsp_PFKEY()
- {
- int i;
- static char *menu[]={
- " MENU1"," MENU2"," MENU3"," MENU4","CD演奏",
- " 選択 "," 削除 "," 確定 "," 複写 "," 通信 " };
-
- for ( i = 0 ; i < 10 ; i++ )
- wrtstr(menu[i],i*7+(i/5),MENU_Y,0x1F);
- }
- void Dsp_status()
- {
- UCHAR tmp[100];
-
- memset(tmp,' ',80); tmp[80] = '\0';
- wrtstr(tmp,0,0,0x1F);
- wrtstr(tmp,0,1,0x1F);
- Dsp_ins_mode();
- Dsp_file_name();
- Dsp_wrt_flg();
- Dsp_free();
- Dsp_PFKEY();
- }
- int Buf_init(file)
- char *file;
- {
- int n;
- FILE *fp;
- UCHAR tmp[512];
-
- top_ptr = lin_ptr = ent_ptr = btm_ptr = 0;
- if ( file != (char *)NULL && (fp = fopen(file,"rb")) != (FILE *)NULL ) {
- wrtstr("ファイルを読み込んでいます",30,1,0x15);
- while ( (n = fread(tmp,1,512,fp)) > 0 ) {
- Ins_buf(btm_ptr,n,tmp);
- btm_ptr += n;
- }
- if ( btm_ptr > 0 && *Cnv_ptr(btm_ptr-1) == '\x1A' )
- Del_buf(--btm_ptr,1L);
- file_name = file;
- fclose(fp);
- wrtstr(SPCSTR,30,1,0x1F);
- } else
- file_name = file;
-
- chk_ptr = cke_ptr = ERR;
- Wrt_flg = FALSE;
- old_wrt_flg = TRUE;
-
- return FALSE;
- }
- int save(file)
- char *file;
- {
- FILE *fp;
- UCHAR tmp[256];
- int n;
- LONG sp,sz;
- char *p;
-
- if ( file != NULL ) {
- file_name = file;
- Dsp_file_name();
- }
- if ( file_name == NULL )
- return ERR;
-
- if ( Back_up != FALSE ) {
- strcpy((char *)tmp,file_name);
- if ( (p = strrchr((char *)tmp,'.')) == NULL )
- for ( p = (char *)tmp ; *p != '\0' ; p++ );
- strcpy(p,".BAK");
- unlink((char *)tmp);
- rename(file_name,(char *)tmp);
- }
-
- if ( (fp = fopen(file_name,"wb")) == NULL )
- return ERR;
-
- for ( sp = 0,sz = btm_ptr ; sz > 0 ; ) {
- if ( sz < 256 ) n = sz; else n = 256;
- Cut_buf(tmp,n,sp);
- fwrite(tmp,1,n,fp);
- sp += n;
- sz -= n;
- }
-
- if ( Apend_Z == FALSE ) {
- tmp[0] = 0x1A;
- fwrite(tmp,1,1,fp);
- }
-
- if ( ferror(fp) ) {
- fclose(fp);
- return ERR;
- }
- fclose(fp);
- return FALSE;
- }
- void Set_file_name(file)
- char *file;
- {
- strcpy(tmp_name,file);
- file_name = tmp_name;
- Dsp_file_name();
- }
- void Set2_file_name(file)
- char *file;
- {
- strcpy(tmp_name,file);
- file_name = tmp_name;
- }
- void main(argc,argv)
- int argc;
- char *argv[];
- {
- int i;
- char tmp[40];
- char *p;
- char *file=NULL;
-
- CONTRL = 0;
- TAB = 8;
-
- #ifdef FMR70
- signal(SIGINT,SIG_IGN);
- #endif
-
- while ( --argc > 0 ) {
- p = *(++argv);
- if ( *p == '-' || *p == '/' ) {
- switch(*(++p)) {
- case 'A': case 'a':
- Auto_log_file = ++p;
- break;
- case 'B': case 'b':
- Back_up = TRUE;
- break;
- case 'Z': case 'z':
- Apend_Z = TRUE;
- break;
- case 'R': case 'r':
- modeW = (modeW & 0xFFF3) | 0x0008;
- break;
- case 'F': case 'f':
- modeW = (modeW & 0xFFCF) | 0x0020;
- break;
- case 'K': case 'k':
- modeW = (modeW & 0xFE3F) | 0x0080;
- break;
- case 'H': case 'h':
- modeW = (modeW & 0xFE3F) | 0x0100;
- break;
- case 'T': case 't':
- Tmp_device_name = ++p;
- break;
- case 'D': case 'd':
- TAB = atoi(++p);
- break;
- }
- } else
- file = p;
- }
-
- Gra_init();
- Dsp_init();
- KAN_open(putstr,putsys,putmode);
- KYB_clic(1);
- Auto_log_init();
- Dsp_status();
- Start_Msg();
-
- if ( Bfp_init() != FALSE ) {
- wrtstr("メモリ管理の初期化に失敗しました",30,1,0x12);
- exit(0);
- }
- if ( Buf_init(file) != FALSE ) {
- wrtstr("ファイルの初期化に失敗しました",30,1,0x12);
- exit(0);
- }
-
- Dsp_status();
- Set_vram();
- Dsp_vram(vram);
-
- if ( (i = setjmp(mark)) != 0 ) {
- sprintf(tmp,"致命的なエラ-が発生しました #%d",i);
- wrtstr(tmp,30,1,0x12);
- }
-
- do {
- while ( edit() == FALSE );
- } while ( Del_wind() == FALSE );
-
- Bfp_end();
- RSB_end();
- KYB_clic(1);
-
- #ifdef TOWNS
- KAN_close();
- CD_endof();
- #endif
-
- #ifdef FMR70
- cprintf("\x1B[2J");
- #endif
- }
-
- #ifdef FMR70
- #include <dos.h>
-
- int KYB_clic(sw);
- int sw;
- {
- union REGS regs;
-
- regs.h.ah = 0x05;
- regs.h.al = sw;
- int86(0x90,®s,®s);
- return;
- }
- int kbhit()
- {
- union REGS regs;
-
- regs.h.ah = 0x07;
- int86(0x90,®s,®s);
- return (int)regs.h.al;
- }
- int KYB_read(sw,ec)
- int sw;
- unsigned *ec;
- {
- union REGS regs;
-
- regs.h.ah = 0x09;
- regs.h.al = sw;
- int86(0x90,®s,®s);
- *ec = regs.x.bx;
- if ( *ec >= 0x5D00 && *ec <= 0x6600 ) {
- regs.h.ah = 0x09;
- regs.h.al = sw;
- int86(0x90,®s,®s);
- *ec = regs.x.bx;
- }
- return regs.x.dx;
- }
- #endif